/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GameLogic;

import java.awt.Color;
import java.awt.Point;
import java.awt.geom.Point2D;
import java.util.*;

public class Mob implements IMob
{
    
    public Game g;
    public MobType type;
    
    public int MaxLife,
               CurLife;
    public double MoveSpeed;
    public double Armor;
    public ArmorType ArmorType;
    
    public double x, y;
    public double DecayTime = 0;
    public boolean isDead = false;
    public int WaypointNum = 0;
    public ArrayList<Point2D> Path;
    public double[] PathLength;
    public int PathNum;
    public double PathPos;
    public TreeMap<Buff, Integer> Buffs = new TreeMap<Buff, Integer>();
    
    public boolean isAlive()
    {
        return !isDead;
    }
    public int getBounty()
    {
        return type.Bounty;
    }
    public Color getColor()
    {
        return type.color;
    }
    public String getName()
    {
        return type.name;
    }
    
    public Mob(MobType mt) 
    {
        type = mt;
        MaxLife = mt.MaxLife;
        CurLife = MaxLife;
        MoveSpeed = mt.MoveSpeed;
        Armor = mt.Armor;
        ArmorType = mt.ArmorType;
    }
    
    public double getDecayTime()
    {
        return DecayTime;
    }
    
    public void onDeath(Tower w)
    {
        
    }
    
    public void onCreate()
    {
        
    }
    
    public void onDecay()
    {
        
    }
    
    
    
    public void DealDamage(Tower dmgSource, double amount, DamageType dt)
    {
        //onDamage
        if(isDead)
            return;
        
        double dmgFactor = IGame.DamageFactor[dt.ordinal()][ArmorType.ordinal()];
        double armorFactor = 1 / (1 + Armor * IGame.ARMOR_MULTIPLIER);
        //System.out.println("Dealt " + amount * dmgFactor * armorFactor + " damage!");
        CurLife -= amount * dmgFactor * armorFactor;
        isDead = CurLife < 0;
        
        if(isDead)
        {
            onDeath(dmgSource);
            DecayTime = DECAYTIME;
            g.MobsAlive--;
            g.PlayerKills++;
            g.PlayerGold += type.Bounty;
        }
    }
    
    public ArmorType GetArmorType()
    {
        return ArmorType;
    }
    
    public int GetCurLife()
    {
        return CurLife;
    }
    public int GetMaxLife()
    {
        return MaxLife;
    }
    public double GetCurMoveSpeed()
    {
        return MoveSpeed;
    }
    public double GetCurArmor()
    {
        return Armor;
    }
    public Point2D GetPosition()
    {
        return new Point2D.Double(x, y);
    }
}
